﻿// -----------------------------------------------------------------------
// Copyright (c) David Kean. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.IO;
using System.Reflection;
using Moq;
using System.Runtime.Serialization;

namespace Portable
{
    public static class AssemblyFactory
    {
        public static Assembly OverrideGetType(Func<string, bool, Type> action)
        {
            var mock = MockFactory.CreateMock<CustomAssembly>();
            mock.Setup(m => m.GetType(It.IsAny<string>(), It.IsAny<bool>()))
                .Returns(action);

            return mock.Object;
        }

        public static Assembly OverrideGetCustomAttributes(Func<bool, object[]> action)
        {
            var mock = MockFactory.CreateMock<CustomAssembly>();
            mock.Setup(m => m.GetCustomAttributes(It.IsAny<bool>()))
                .Returns(action);

            return mock.Object;
        }

        public static Assembly OverrideGetCustomAttributes(Func<Type, bool, object[]> action)
        {
            var mock = MockFactory.CreateMock<CustomAssembly>();
            mock.Setup(m => m.GetCustomAttributes(It.IsAny<Type>(), It.IsAny<bool>()))
                .Returns(action);

            return mock.Object;
        }

        public static Assembly OverrideIsDefined(Func<Type, bool, bool> action)
        {
            var mock = MockFactory.CreateMock<CustomAssembly>();
            mock.Setup(m => m.IsDefined(It.IsAny<Type>(), It.IsAny<bool>()))
                .Returns(action);

            return mock.Object;
        }

        // To make Moq happy
        public class CustomAssembly : Assembly
        {
            public CustomAssembly()
            {
            }

            protected CustomAssembly(SerializationInfo info, StreamingContext context)
            {
            }
        }
    }
}
